/**
 * 缓存路由
 */
import { _decode } from '@/common/js/tool.js'
const keepList = {
  state: {
    include: [], //缓存路由
    exclude: [], //不缓存路由
    visitedViews: []
  },
  mutations: {
    ADD_KEEP_VIEWS: (state, view) => {
			if(state.include.indexOf(view)>-1) return
			state.include.push(view)
    },
		
    DEL_KEEP_VIEWS: (state, view) => {
			state.include.some((item,idx)=>{
				if(item==view){
					 state.include.splice(idx, 1)
				}
			})
    },
		
    DEL_OTHERS_VIEWS: (state, view) => {
      state.visitedViews = state.visitedViews.filter(v => {
        return v.meta.affix || v.path === view.path
      })
    },
    DEL_ALL_VIEWS: state => {
      const affixTags = state.visitedViews.filter(tag => tag.meta.affix)
      state.visitedViews = affixTags
    },
    UPDATE_VISITED_VIEW: (state, view) => {
      for (let v of state.visitedViews) {
        if (v.path === view.path) {
          v = Object.assign(v, view)
          break
        }
      }
    }
  },
  actions: {
    addKeepViews({ commit }, view) {
      // commit('ADD_KEEP_VIEWS', view)
      commit('ADD_KEEP_VIEWS', view)
    },
    delKeepViews({ commit, state }, view) {
      return new Promise(resolve => {
        commit('DEL_KEEP_VIEWS', view)
      })
    },
    
  },
	getters: {
	  getKeepIncludelList(state) {
	    return state.include
	  }
	  
	}
}

export default keepList
